#include <stdio.h>
#include <stdlib.h>

void add_data(node*,int); 
void allocate_space(node*);
typedef struct _node{
	int data;
	struct _node*next; 
}node;

void add_data(node*p,int num)
{
	p->data = num;
}
void allocate_space(node* p)
{
	p = (node*)malloc(sizeof(node));
      	
}	
int main(void)
{
	node*a,*b,*c,*d,*e,*p,*y,*q;     
        allocate_space(a);
        allocate_space(b);
        allocate_space(c);
        allocate_space(d);
        allocate_space(e);
        allocate_space(p);
        allocate_space(y);
        allocate_space(q);
	a->next = b;
        b->next = c;
        c->next = d;
        d->next = e;
        e->next = NULL;

        add_data(b,1);
        add_data(c,2);
        add_data(d,4);
        add_data(e,9);
        add_data(y,122);
        printf("%d\t%d\t%d\t%d\t\n",b->data,c->data,d->data,e->data);
	printf("y:%p\n",y);
        
	p = a;  //遍历
	while (p->next->data != 9)	
	{
	    p = p->next;	    	    
	}   
	printf("%d\n",p->data);

	p = a; //插入  
	for (int i =0;i < 3;i++)
	{
	    p = p->next;
            printf("%d\n",p->data);
	}
	    y->next = p->next;
	    p->next = y;
	printf("y:%p\n",y);
	p = a ;    
	while (p->next !=NULL)
	{
	    p = p->next;	
            printf("%d\n",p->data);
	}    

	p = a;
        while (p->next->data !=122)//删除
        {
	    p = p->next;	    
	}
	    q = p->next;
	    p->next = p->next->next;
	    free(q);
	p = a ;    
	while (p->next !=NULL)
	{
	    p = p->next;	
            printf("%d\n",p->data);
	}    
        printf("y:%p\n",y->next); 
        printf("q:%p\n",q->next); 
        printf("d:%p\n",d->next); 
        printf("y:%d\n",y->data); 
        printf("q:%d\n",q->data); 

	return 0;
}	
